package com.itheima.wms.controller;

import com.itheima.wms.pojo.PageWareHouse;
import com.itheima.wms.pojo.WmsArea;
import com.itheima.wms.service.WareHouseService;
import com.itheima.wms.utils.PageBean;
import com.itheima.wms.utils.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(path = "/area")
public class WareHouseController {
    private final WareHouseService wareHouseService;

    /**
     * 分页查询
     */
    @GetMapping(path = "/pageDetail")
    public Result<PageBean<WmsArea>> queryWareHouseAll(PageWareHouse pageWareHouse) {
        PageBean<WmsArea> wmsArea = wareHouseService.queryFactoryAll(pageWareHouse);
        return Result.success(wmsArea);
    }

    /**
     * 新增库区
     */
    @PostMapping
    public Result<String> addWareHouse(@RequestBody WmsArea wmsArea) {
        wareHouseService.addWareHouse(wmsArea);
        return Result.success("新增成功");
    }

    /**
     * 修改回显
     */
    @GetMapping(path = "/{id}")
    public Result<WmsArea> queryWareHouseById(@PathVariable("id") Integer id) {
        WmsArea wareHouse = wareHouseService.queryWareHouseById(id);
        return Result.success(wareHouse);
    }

    /**
     * 修改库区
     */
    @PutMapping
    public Result<String> updateWareHouse(@RequestBody WmsArea wmsArea) {
        wareHouseService.updateWareHouse(wmsArea);
        return Result.success("修改成功");
    }

    /**
     * 删除库区
     */
    @DeleteMapping
    public Result<String> delete(@RequestParam("ids[]") List<Long> ids) {
        log.info("删除库区:{}", ids);
        wareHouseService.deleteWareHouse(ids);
        return Result.success("操作成功");
    }

}
